<form id="addIdenManageForm" lay-filter="editGroupForm" class="layui-form model-form">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入名称" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">编码</label>
        <div class="layui-input-block">
            <input name="code" placeholder="请输入编码" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">对象分类</label>
        <div class="layui-input-block">
            <select name="metaType" placeholder="请选择对象分类" id="metaType">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">报告期</label>
        <div class="layui-input-block">
            <select name="reportType" placeholder="请选择报告期" id="reportType">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">指标模板</label>
        <div class="layui-input-block">
            <select name="mitid" placeholder="请选择指标模板" id="mit">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">报送开始时间</label>
        <div class="layui-input-block">
            <input name="startTime" type="text" class="layui-input" id="startTime" placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">报送结束时间</label>
        <div class="layui-input-block">
            <input name="endTime" type="text" class="layui-input" id="endTime" placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">报送地点</label>
        <div class="layui-input-block">
            <input name="localeOfSubmission" placeholder="请输入报送地点" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否支持多版本数据导入</label>
        <div class="layui-input-block">
            <input type="checkbox" checked name="datavIsMulti" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary layui-btn-sm" type="button" ew-event="closePageDialog">取消</button>
        <button class="layui-btn layui-btn-sm" lay-filter="add-index" lay-submit >确定</button>
    </div>
</form>
<!--渲染对象分类-->
<script type="text/tmpl" id="template-meta_type-tmpl">
     {{each meta_type}}
        <option value="{{$value.value}}">{{$value.meta_type}}</option>
    {{/each}}
</script>
<!--渲染报告期分类-->
<script type="text/tmpl" id="template-report_type-tmpl">
     {{each report_type}}
        <option value="{{$value.value}}">{{$value.report_type}}</option>
    {{/each}}

</script>
<!--渲染指标模板-->
<script type="text/tmpl" id="template-mit-tmpl">
     {{each mit}}
        <option value="{{$value.id}}">{{$value.name}}</option>
    {{/each}}

</script>
<script>
    layui.use(['layer', 'form', 'admin','tree','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var tree = layui.tree;
        var laydate = layui.laydate;
        var Authorization;
        var userInfo = getAuthority();
        //获取权限方法
        if(userInfo){
            var access_token = localStorage.getExpire("access_token");
            var token_type = localStorage.getExpire("token_type");
            Authorization = token_type+" "+access_token;
        }
        var mUser = window.mSelUser;  // 列表页面传递的数据，也可以使用top.xxx
        //日期时间选择器
        laydate.render({
            elem: '#startTime'
            ,type: 'datetime'
        });

        laydate.render({
            elem: '#endTime'
            ,type: 'datetime'
        });
        var meta_type;
        meta_type = mUser.meta_type
        var str = template("template-meta_type-tmpl",{meta_type});
        document.getElementById("metaType").innerHTML = str;

        var report_type;
        report_type = mUser.report_type
        var str = template("template-report_type-tmpl",{report_type});
        document.getElementById("reportType").innerHTML = str
        getMitid();
        //获取所有指标模板
        function getMitid(){
            var req={
                current: 1,
                size: 10000,
            };
            axios.get(microUrl.template.queryList,{
                params: req,
                headers:{
                    'Authorization':Authorization
                }
            })
                .then(function (response) {
                    if(response.status == 200 &&response.data.message == "success"){
                        var data = response.data.data;
                        var mit;
                        mit = data.records
                        var str = template("template-mit-tmpl",{mit});
                        document.getElementById("mit").innerHTML = str
                        form.render('select')
                    }
                })
                .catch(function (error) {
                    console.log(error);
                    if(error.response.status === 401 || error.response.status === 403 || error.response.status === 406){
                        // 进行重新登陆
                        localStorage.clear();
                        top.location.href=loginPageUrl;
                    }
                });
        }
        form.render('select')
        form.render('checkbox')
        // 表单提交事件
        form.on('submit(add-index)', function (data) {
            data.field.menuId = mUser.parent_id;
            data.field.datavIsMulti = data.field.datavIsMulti?'1':'0'

            axios({
                method: 'post',
                data:data.field,
                url:microUrl.microObject.microList.addMicroList,
                headers:{
                    'Authorization':Authorization
                }
            })
                .then(function (res) {
                    if (res.status == 200&&res.data.message=="success") {
                        layer.closeAll('loading');
                        layer.msg("新增成功", {icon: 1});
                    } else {
                        layer.msg(res.data.message, {icon: 2});
                        layer.closeAll('loading');

                    }
                    admin.closeDialog('#addIdenManageForm');
                })
                .catch(function (error) {
                    console.log(error);
                    if(error.response.status === 401 || error.response.status === 403 || error.response.status === 406){
                        // 进行重新登陆
                        localStorage.clear();
                        top.location.href=loginPageUrl;
                    }
                })
            return false;

        });

    });
</script>